<?
include 'common/header.html';
include 'common/left.html';
include 'common/autoload.php';
include 'common/Prod_Common.php';
include 'common/prodField.php';

$isedit = false;// 是否编辑进入
$lid = abs($_GET['sid']);// 景区ID
$jiutian_f = false;// 是否需要绑定九天闸机
$ticket_id = abs($_GET['prod_id']);// 产品ID，编辑进入

// 返回列表按钮
$gourl = 1;

if(!$lid && !$ticket_id) exit('<script>alert("访问参数出错");history.go(-1);</script>');
$apply_did = $_SESSION['sid'];// 供应商ID


// 身份验证
if($_SESSION['sdtype']!=9){
    if($_SESSION['dtype']==6 && $_SESSION['sdtype']!=0){
		$msg = ($_SESSION['dtype']==6) ? '您的上级不是供应商身份，无法发布产品':'您不是供应商身份，无法发布产品';
		exit('<script>alert("'.$msg.'")</script>');
	}
	$sql = "select apply_did from uu_land where id=$lid limit 1";
	$GLOBALS['le']->query($sql);
    $GLOBALS['le']->fetch_assoc();
    if($GLOBALS['le']->f('apply_did')!=$apply_did) exit('<script>alert("这不是你的产品")</script>');
}

// 员工权限
if($_SESSION['dtype']==6 && strpos($_SESSION['qx'],'upProd')===false){
    exit('<script>alert("您无权访问这个页面")</script>');
}

$obj = new pft\Prod\Product($GLOBALS['le']);

if($ticket_id){
    $isedit = true;
    $data = ($_SESSION['sdtype']==9) ? $obj->GetTicketById($ticket_id):$obj->GetTicketById($ticket_id, $apply_did);
    $apply_did = $data['apply_did'];// 实际产品供应商ID
    $data_f = $obj->GetProdcutExt($ticket_id);//扩展表里面的数据
    $ass = '';// 集合地点
    if($data_f['ass_station']) $ass = implode(';',unserialize($data_f['ass_station']));
    $tid = $data['id'];
    $pid = $data['pid'];
    $pobj = new Price($pid);
    $titleText = $data['title'];
    $navText = '门票编辑';
    $startplace = $data_f['startplace'];
    $endplace = $data_f['endplace'];
}

// 获取景区信息
$scenryData = $obj->GetSceneryTitle($lid);
$ptype = $scenryData['p_type'];
$notify_num = $scenryData['fax'];
if($ptype=='B' && !$ticket_id) {
    $startplace = substr($scenryData['runtime'],0,strpos($scenryData['runtime'],'|'));
    $endplace = substr($scenryData['runtime'],strpos($scenryData['runtime'],'|')+1);
}
$titleText = $scenryData['title'].'--'.$titleText;

// 按钮
if($data['sync_id'] && $data['sync_status']==2){
    $btnWrap = '同步的产品禁止修改操作';
}else{
    $btnWrap = '<button class="ui-button ui-button-lblue" id="saveTicket" type="button">保存</button>';
}

//查询是否有给绑定闸机的权限
$str_ticket = "SELECT jiutian_auth FROM pft_member_extinfo WHERE fid=$apply_did limit 1";
$GLOBALS['le']->query($str_ticket);
$GLOBALS['le']->fetch_assoc();
$jiutian_auth =  $GLOBALS['le']->f('jiutian_auth');

// 需要绑定闸机的产品ID（tid）
$needBind = array(
	'1976',	'4314',	'4313',	'5604',	'5603',	'5523',	'5522',	'5521',	'5520',	'3950',	'3949',	'3911','5857','5818','5817','5816','6047','6049','5959','5958','5957','6060','6059','6062','6061','6044','6042','4313','4314','5567','7177','9746','6042','6044','9833','9832','9962','10003','9962','9963','9964','9965','9904','9948','9949','9901',
'9873','9874','9862','9863','9836','9837','9855','9856','9830','9831','9829','9826','9809','9810','9811','9812','10004','10392','10405'
);
if($jiutian_auth == 1 || in_array($_REQUEST['prod_id'],$needBind) || $_SESSION['sid']==7132){ 
	// 绑定闸机票类数据（自己生成，九天不提供）
	$tmp = array();
	$md5 = md5($scenryData['title'].'-'.$_REQUEST['prod_id']);
	$jiuTians[] = array('uuid'=>$md5,'name'=>$data['title']);
    $jiutian_f = true;
}

if($_SESSION['sid'] == 7517 ){// 鼓浪屿绑定闸机票类数据
	$jiuTians = file_get_contents('http://117.29.178.154:8000/et/ebusiness/ticketInfo.do');
	$jiuTians = json_decode($jiuTians,true);
    $jiuTians = $jiuTians['content'];
    $jiutian_f = true;
}
if($ptype=='F') {
	$jiutian_f = false;
	$package_data = $scenryData['attribute'];
	$package_data = $obj->PackageDataFormat($package_data);
	$pack = new PackTicket($lid);
	if(!$pack->checkEffectivePack()) exit('子票信息冲突');
	$advance = $pack->advance;// 提前天数
	$paymode = $pack->paymode;// 支付方式
	
	$saleScene = false;
	$get_account_group = "select group_id from pft_member where id={$_SESSION['sid']} limit 1";
	$GLOBALS['le']->query($get_account_group);
	$GLOBALS['le']->fetch_assoc();
	$group_id = $GLOBALS['le']->f('group_id');
	if($group_id==4){
		$saleScene = true;// 云顶允许打包现场支付
	}
	if($paymode==0 && !$saleScene) exit('现场支付不支持打包');
}
	
// 页面参数
$var['payScene'] = ($ptype=='F') ? false:true;// 允许现场支付
$var['payOnline'] = true;// 允许在线支付
if($ptype=='F' && $group_id==4 && $paymode==0){
	$var['payScene'] = true;
	$var['payOnline'] = false;
}
$advance = 0;// 提前天数
$cancel_cost[0]= array('c_type'=>1,'c_cost'=>'','c_days'=>'');


?>
<link rel="stylesheet" href="http://www.12301.cc/css/aliceui.min.css"/>
<link rel="stylesheet" href="http://www.12301.cc/css/resetui.css"/>
<link rel="stylesheet" href="http://www.12301.cc/css/product_publish.css?body=1"/>
<link rel="stylesheet" href="http://www.12301.cc/css/prod_store.css"/>
<link rel="stylesheet" href="http://www.12301.cc/css/my_color.css"/>
<link rel="stylesheet" href="http://www.12301.cc/css/easydialog.css"/>
    <div class="wrapper">
    <h3 class="mc_title">
        <span class="mctit_1"><span class="mctit_2">票类编辑</span></span>
    </h3>
    <?if(!$isedit):?>
        <ol class="ui-ministep step3">
            <li class="ui-ministep-item"><span class="ui-ministep-text">产品类型</span></li>
            <li class="ui-ministep-item"><span class="ui-ministep-text"><?=$FieldList[$ptype]['ticket']['t4']?></span></li>
            <li class="ui-ministep-item ui-ministep-active">
                <span class="ui-ministep-text"><?=$FieldList[$ptype]['ticket']['t1']?></span>
            </li>
        </ol>
    <?endif;?>
    <form class="ui-form" name="branchForm" id="branchForm">
    <input type="hidden" name="did" value="<?=$apply_did?>">
    <input type="hidden" name="lastid" value="<?=$lid?>"/>
    <input type="hidden" name="action" value="CreateNewTicket"/>
    <input type="hidden" name="f[fid]" value="<?=$data_f['id']?>"/>
    <input type="hidden" name="step" value="2"/>
    <input type="hidden" name="ptype" value="<?=$ptype?>"/>
    <input type="hidden" name="chk_state" value="<?=$data['apply_limit']?>"/>
    <input type="hidden" name="pid" value="<?=$data['pid']?>"/>
    <input type="hidden" name="tid" value="<?=$data['id']?>"/>
    <input type="hidden" name="ser_date" value="<?=date('Ymd')?>"/>
    <input type="hidden" name="pft_rflex_id" value="<?=$data['pft_rflex_id']?>"/>
    <input type="hidden" name="iscopy" value="<?=$iscopy?>"/>
    <?=$saveByAdminInput?>
    <div class="ui-tipwrap" id="RefuseMsgWrapper">
        <div class="ui-tipbox ui-tipbox-error">
            <div class="ui-tipbox-content">
                <h3 class="ui-tipbox-title"></h3>
                <p class="ui-tipbox-explain" id="RefuseReason"></p>
            </div>
        </div>
    </div>
    <?
    if($ptype=='F') {
       
        include TPLPATH .'_package_box.html';
    }
    ?>
    <table id="pros_tbl" class="prod_laun"><!--常用属性-->
	<caption><h3>产品名：<?=$scenryData['title']?></h3></caption>
	<thead><tr class="header"><th colspan="2" class="th_n">常用属性</th></tr></thead>
	<tbody class="fixed_th_width">
    <tr>
        <th id="th_1">付款方式</th>
        <td data-hide="<?=$data['pay']?>">
            <?if($var['payOnline']):?>
            <label><input type="radio" class="vn_middle" value="1" <?=($data['pay']==1)?'checked="checked"':''?> name="payType" id="payType1" />在线支付</label>
			<input type="text" class="input-text w40 chknum" name="cancel_time" value="<?=$data['cancel_auto_onMin']?>">分钟未支付自动取消&nbsp;&nbsp;
			<?endif;?>
            <?if($var['payScene']):// 套票不支持现场支付?>
            <label><input type="radio" class="vn_middle" value="0" <?=($data['pay']==0)?'checked="checked"':''?> name="payType" onChange="evolution_check(this,<?=$data['pid']?>)" />现场支付</label>
            <?endif;?>
        </td>
    </tr>
	<?if($ptype!='F'):// 判断套票不需要有效期开始?>
    <tr>
        <th id="th_2">使用有效期</th>
        <? $utx = $ptype=='C'? '入住日期':'游玩日期'?>
        <td>
            <label><input data-delay="<?=$data['delaydays']?>" type="radio" name="validTime" <?=!$data['delaydays']?'checked="checked"':''?> value="0"/><?=$utx?>当天有效</label>&nbsp;&nbsp;
            <?if($ptype=='A' || $ptype=='C' || $data['delaydays']>0):?>
            <input type="radio" id="radio1" name="validTime" <?=$data['delaydays']>0?'checked="checked"':''?> value="<?=($data['delaytype']==0) ? 1:2;?>" /> 
				<select  id="btn1" >
                        <option value="1" <?if($data['delaytype']==0) echo 'selected="selected"'?>> 游玩日期(含)</option>
                        <option value="2" <?if($data['delaytype']==1) echo 'selected="selected"'?>> 下单日期</option>  
                </select>之后<input id="btn3" class="input-text w40 chknum" type="text" name="vt" value="<?=$data['delaydays']>0?$data['delaydays']:''?>">天内有效&nbsp;&nbsp;
            <?endif;?>
			<label>
			<input type="radio" id="radio2" name="validTime" data-ord="<?=$data['order_start']?>" <?if(strtotime($data['order_start'])>0 || strtotime($data['order_end'])>0) echo 'checked="checked"'?> value="3"/>开始日期<input type="text" data-t="bt" id="btn4" data-msg="请选择时间段" value="<?=substr($data['order_start'],0,10)?>"  name="order_start" class="required input-text w66"  onfocus="WdatePicker({minDate:'%y-%M-{%d}'})"/> 至
		<input type="text" data-t="bt" id="btn2" data-msg="请选择时间段" value="<?=substr($data['order_end'],0,10)?>"  name="order_end" class="required input-text w66"  onFocus="WdatePicker({minDate:'#F{$dp.$D(\'btn4\')}',maxDate:'2020-10-01'})"/>
		有效</label>
        </td>
    </tr>
	<?endif;// 判断套票不需要有效期结束?>
    <tr>
        <th id="th_3">提前预定</th>
		<td>
			需提前
			<span class="ui-form-explain"><input type="text" class="input-text w40 chknum" name="earyTime" value="<?=isset($data['ddays'])?$data['ddays']:$advance?>"></span>天，在
			<select name="f[dhour]">
			<?for($i=23;$i>=0;$i--){?>
				<option value="<?=$i?>" <?=isset($data_f['dhour']) && substr($data_f['dhour'],0,-4)==$i?'selected="selected"':''?>><?=$i.':59'?></option>
			<?}?>
			</select>前预定
        </td>
    </tr>
	<?if($_SESSION['sid']==1433):?>
	<tr>
		<th id="th_3">预售天数</th>
		<td><span class="ui-form-explain"><input type="text" class="input-text w40 chknum" name="max_days" value="<?=isset($data['max_order_days']) ? $data['max_order_days']:0?>"></span>天的票
		<span class="ui-form-explain">提前预售天数，填“-1”表示无限制</span></td>
	</tr>
	<?endif;?>
	<?if($ptype=='A' || $ptype=='F'):// 门票属性?>
	<tr>
		<th id="th_6"><span class="ui-form-required">*</span>取票信息</th>
		<td>
			<input type="text" id="ticket_val" value="<?=$data['getaddr']?>" title="请输入取票信息" name="TicketInfo" class="input-text w500" data-required="1">
			<span class="ui-form-explain">此信息将在游客手机短信上显示</span>
		</td>
	</tr>
	<tr>
		<th id="th_7">产品说明</th>
		<td>
			<textarea name="TicketExplain" class="input-text w500" style="height: 50px;"><?=$data['notes']?></textarea>
		</td>
	</tr>
    <?endif;// 门票属性结束?>
	
    <?if($ptype=='B')://线路属性?>
	<tr>
		<th>
			<span class="ui-form-required">*</span>游玩天数
		</th>
		<td>
			<input class="input-text w40 chknum" data-required="1" title="请输入游玩天数" type="text" name="f[rdays]" id="tourDays" value="<?=$data_f['rdays']?>">天
			<span class="ui-form-explain">请填写大于0的数字</span>
			<input class="input-text" name="f[beginPlace]" id="beginPlace"  type="hidden" placeholder="出发地" value="<?=$startplace?>">
			<input class="input-text" name="f[endPlace]" type="hidden" placeholder="目的地" value="<?=$endplace?>">
		</td>
	</tr>
	<tr>
		<th>团号</th>
		<td>
			<?
				$prefix = substr($data_f['series_model'],0, strpos($data_f['series_model'],'{'));
				$endfix = substr($data_f['series_model'],strpos($data_f['series_model'],'}')+2);
			?>
			<input type="text" name="grp_num1" class="grp_num input-text w50" value="<?=$prefix?>"/>
			+出团日期+出团编号
			<select name="grp_num2" class="grp_num">
				<option value="">选择</option>
				<?for($i=1;$i<=10;$i++){ $code = str_pad($i, 2,'0',STR_PAD_LEFT);?>
					<option value="<?=$code?>" <?=$endfix==$code?'selected="selected"':''?>><?=$code?></option>
				<?}?>
			</select>
			预览：<span id="prev_grp_num"><?=!empty($data_f['series_model'])?str_replace('{fck_date}', date('Ymd'),$data_f['series_model']):''?></span>
		</td>
	</tr>
	<tr>
		<th><span class="ui-form-required">*</span>集合地点</th>
		<td>
			<textarea cols="100" rows="4" id="ass_station" name="f[ass_station]"><?=$ass?></textarea>
			<p class="ui-form-explain">填写集合地点、集合时间及导游手机，<span class="red">多个集合地点请用<strong>分号</strong>（;）分隔</span></p>
		</td>
	</tr>
    <?endif;// 线路属性结束?>
	
    <tr><!--票类名称-->
        <th id="th_0"><span class="ui-form-required">*</span><?=$FieldList[$ptype]['ticket']['ticketType']?></th>
        <td>
            <input type="text" name="tTitle" class="input-text w300" data-required="1" title="请输入<?=$pname?>名称" value="<?=!empty($_GET['c_title'])?urldecode($_GET['c_title']):$data['title']?>">
			<?if($jiutian_f):// 九天闸机对接?>
			<span class="ui-form-required">*</span>
			<span>关联线下票类</span>
			<select name="gate">
				<option value="" > 请选择 </option>
                <?foreach($jiuTians as $key=>$jiuTian):?>
                    <?if($data['uuid']==$jiuTian['uuid']):?>
                    <option value="<?=$jiuTian['uuid']?>" selected="selected"><?=$jiuTian['name']?></option>
                    <?else:?>
                    <option value="<?=$jiuTian['uuid']?>" ><?=$jiuTian['name']?></option>
                    <?endif?>
                <?endforeach;?>
			</select>
			<?endif?>
        </td>
    </tr>
    </tbody>
    </table><!--常用属性 end-->
	
    <table class="prod_laun" id="tab"> <!--扩展属性-->
        <thead><tr class="header"><th class="th_n">扩展属性</th><td class="td_n"></td></tr></thead>
        <tbody class="fixed_th_width">
        <tr>
			<th>取消费用</th><!--取消费用通用配置-->
            <td>
				<span class="number_style">
				<select id="testtt" onchange="checka(this)" name="reb_type">
                    <option value="0">售价百分比</option>
                    <option value="1" <?if($data['reb_type']==1) echo 'selected="selected"'?>>固定金额</option>
				</select>
                </span>
                <input type="text" name="reb" class="input-text w40 chknum" value="<?=($data['reb_type'])? $data['reb']/100:$data['reb']?>"/>
                <span class="number_stylea"><?=$data['reb_type']=='1'?"元":"%"?></span>
                <span class="ui-form-explain">取消订单需要收取的费用百分比，填“0”代表不收取费用。</span>
            </td>
        </tr>
		<?if($access['yd']):?>
        <?if($data['cancel_cost']!='') $cancel_cost = json_decode($data['cancel_cost'],true);?>
        <?foreach($cancel_cost as $key=>$val):?>
        <tr id="x" class="xun"><!--阶梯取消费用-->
            <th>梯度取消费用</th>
            <td>游玩日期前
				<input type="hidden" name="reb_days[]" class="turn_reb_daya" value="<?=$val['c_days']?>" data-day="<?=$val['c_days']?>">
                <input type="text"  class="input-text w40 chknum spe_text" value="<?=$val['c_days']/1440?>" data-type="<?=$access['yd']?"0":"1"?>"/><?=$access['yd']?"天":"分钟&nbsp;"?>收取
				<select name="reb_type[]" id="testtt" class="xund" onchange="check(this)">
					<option value="0" >固定值</option>
					<option value="1" <?if($val['c_type']==1) echo 'selected="selected"';?> >百分比</option>
				</select>
				<input type="text" name="reb_cost[]" class="input-text w40 chknum" value="<?=$val['c_cost']?>"/>
				<span class="number_style"><?=$val['c_type']=='1'?"%":"元"?></span>
                <span class="ui-form-explain">取消费用可选固定值或票价的百分比来设定取消费用</span>
				<span><input type="button"  class="btn_addtr" value="添加"></span>
				<span><input type="button"  class="del" value="删除"></span>
            </td>
        </tr>
        <?endforeach;?>
		<?endif;?>

        <?if($ptype=='A'):// 产品类型为A的验证时间?>
        <tr>
            <th>验证时间</th>
            <td colspan="2" data-tl="<?=$data_f['v_time_limit']?>">
            <?	$span_v_time_limit = 'hide';
				if($data_f['v_time_limit']) {
					$vt = explode('|', $data_f['v_time_limit']);
					$vtb = substr($vt[0], 0, strpos($vt[0],':'));
					$vte = substr($vt[1], 0, strpos($vt[1],':'));
					$span_v_time_limit = 'show';
				}
			?>
            <label>
				<input type="radio" value="0" name="v_time_limit" <?=$data_f['v_time_limit']==0 ? 'checked="checked"':''?>/>不限
			</label>
            <label>
				<input type="radio" value="1" name="v_time_limit" <?=$data_f['v_time_limit']!=0 ? 'checked="checked"':''?>/>自定义
			</label>
			
			<span id="span_v_time_limit" style="display: <?=$span_v_time_limit?>;">
				<select id="v_tl_1" name="vt1">
					<?for($i=1; $i<=23; $i++):?>
					<option value="<?=$i . ':00'?>" <?=($i==$vtb? 'selected':'')?>><?=$i.':00'?></option>
					<?endfor;?>
				</select>至
				<select id="v_tl_2" name="vt2">
					<?for($i=1; $i<=23; $i++):?>
					<option value="<?=$i . ':00'?>" <?=($i==$vte? 'selected':'')?>><?=$i.':00'?></option>
					<?endfor;?>
				</select>
			</span>
            <span class="ui-form-explain">限制日场票或夜场票的验票时间，间隔必须大于1小时</span>
            </td>
        </tr>
        <tr>
            <th>可验证日期</th>
            <td colspan="2">
                <?$order_limit = explode(',',$data['order_limit']);?>
                <label><input type="checkbox" <?if(!in_array(1,$order_limit))echo 'checked="checked"'?> name="verify_limit[]" class="pday" value="1">日</label>
                <label><input type="checkbox" <?if(!in_array(2,$order_limit))echo 'checked="checked"'?> name="verify_limit[]" class="pday" value="2">一</label>
                <label><input type="checkbox" <?if(!in_array(3,$order_limit))echo 'checked="checked"'?> name="verify_limit[]" class="pday" value="3">二</label>
                <label><input type="checkbox" <?if(!in_array(4,$order_limit))echo 'checked="checked"'?> name="verify_limit[]" class="pday" value="4">三</label>
                <label><input type="checkbox" <?if(!in_array(5,$order_limit))echo 'checked="checked"'?> name="verify_limit[]" class="pday" value="5">四</label>
                <label><input type="checkbox" <?if(!in_array(6,$order_limit))echo 'checked="checked"'?> name="verify_limit[]" class="pday" value="6">五</label>
                <label><input type="checkbox" <?if(!in_array(7,$order_limit))echo 'checked="checked"'?> name="verify_limit[]" class="pday" value="7">六</label>
            </td>
        </tr>
        <?endif;// 产品类型为A的验证时间 end?>
		<?if(-1==1):?>
		<tr>
            <th>身份证验证</th>
            <td>
                <label><input type="radio" class="vn_middle" value="0" <?=!isset($data_f)||$data_f['v_ID_support']==0?'checked="checked"':''?> name="f[v_ID_support]" />不支持</label>
                <label><input type="radio" class="vn_middle" onclick="return confirm('您确定终端已经支持身份证验证了吗？')" value="1" <?=$data_f['v_ID_support']==1?'checked="checked"':''?> name="f[v_ID_support]" />支持</label>
                <span class="ui-form-explain">开启身份证验证需终端支持。</span>
            </td>
        </tr>
		<?endif;?>
        <tr>
            <th>通知供应商</th>
            <td>
                <label><input type="radio" name="f[confirm_sms]" value="0" <?=!$data_f['confirm_sms']?'checked="checked"':''?>/>否</label>
                <?php
                    if(!isset($data)){
                        $dis_sms = 'disabled="disabled"';
                        $dis_sms_cl = 'disable';
                    }
                    if(isset($data_f['confirm_sms']) && $data_f['confirm_sms']==1){
                        $chk_sms = 'checked="checked"';
                    }
                ?>
                <label class="<?=$dis_sms_cl?>"><input type="radio" name="f[confirm_sms]" value="1" <?=$chk_sms?> <?=$dis_sms?>/>是</label>
                <span class="ui-form-explain">新订单是否短信通知供应商</span>
                通知手机： <input type="text" maxlength="11" id="notify_num" readonly="readonly" class="notify_num" value="<?=$notify_num?>"/>
                <a id="edit_notify_num" href="javascript:">编辑</a>
                <a id="cancel_edit_num" style="display: none;" href="javascript:">取消</a>
                <span id="edit_res"></span>
            </td>
        </tr>
        <tr>
            <th>发送凭证码</th>
            <td>
                <label><input type="radio" name="sendVoucher" value="0" checked="checked"/>是</label>
                <label><input type="radio" name="sendVoucher" value="1" <?if($data_f['sendVoucher']==1)echo 'checked="checked"';?>/>否</label>              
                <span class="ui-form-explain">是否发送短信（凭证码)到取票人手机</span>
            </td>
        </tr>
       <!--  <tr>
            <th>产品介质</th>
            <td>
                <label><input type="radio" class="vn_middle" value="0" <?=!isset($data)||$data['ifs']==0?'checked="checked"':''?> name="ticketMedia" />电子票</label>
                <label><input type="radio" class="vn_middle" value="1" <?=$data['ifs']==1?'checked="checked"':''?> name="ticketMedia" />实体票（需寄送）</label>
            </td>
        </tr> -->
        <tr>
            <th>游客信息</th>
            <td>
                <label><input type="radio" name="f[tourist_info]" <?=!$data_f['tourist_info']?'checked="checked"':''?> value="0"/>无需填写</label>
                <label><input type="radio" name="f[tourist_info]" <?=$data_f['tourist_info']==1?'checked="checked"':''?>value="1"/>只需填写一位游客信息</label>
                <label><input type="radio" name="f[tourist_info]" <?=$data_f['tourist_info']==2?'checked="checked"':''?>value="2"/>需填写所有游客信息</label>
                <span class="ui-form-explain">游客信息指游客姓名及身份证号</span>
            </td>
        </tr>
        <?if($access['yd']):// 云顶点评返现?>
        <tr>
            <th>点评返积分</th>
            <td>返<input type="text" name="integral" class="input-text w40 chknum" style="height:16px;" value="<?=$data['re_integral']?>"/>积分</td>
        </tr>
        <?endif;// 云顶点评返现?>
        <tr>
            <th>一次最少</th>
            <td><input type="text" name="blimit_low" class="input-text w40 chknum" value="<?=isset($data) ? $data['buy_limit_low']:'1'?>"/>张<span class="ui-form-explain">一次最少购买的票数</span>
            </td>
        </tr>
        <tr>
            <th>一次最多</th>
            <td>
                <input type="text" name="blimit_up" class="input-text w40 chknum " value="<?=isset($data)?$data['buy_limit_up']:'0'?>"/>张
                <span class="ui-form-explain">一次最多购买的票数，填“0”代表不限</span>
            </td>
        </tr>
        <tr>
            <th>微信通知</th>
            <td>
                <label><input type="radio" name="confirm_wx" value="0" id='confirm_wx0' checked="checked"/>否</label>
                <label><input type="radio" name="confirm_wx" value="1" id='confirm_wx' <?if($data_f['confirm_wx']==1)echo 'checked="checked"';?>/>是</label>
                <span class="ui-form-explain">是否发送订单通知到微信</span>
                <a style='margin-left:10px' />请到手机端关注票付通官方微信
            </td>
        </tr>
        </tbody>
    </table>

    <table class="prod_laun" id="price_tb">
        <thead>
        <tr class="header">
            <th colspan="8">
                <span style="float:right;margin-right: 10px;margin-top: 2px; margin-top:0\9">
                    <button type="button" class="newprice ui-button ui-button-sorange">添加</button>
                </span>
                价格/库存配置[<a style="font-size: 12px;font-weight:normal;" target="_blank" href="storageConfig.html?pid=<?=$data['pid']?>">使用“日历模式”</a>]
                <?= $background ? '[<a style="font-size: 12px;font-weight:normal;" href="http://www.16u.cc/d/prod_invalid_price.html?pid='.$prod_id.'&token='.md5(date('Ymd').'cgp').'" target="_blank">历史记录</a>]':''?>
            </th>
        </tr>
        <tr class="bo_btn price_header">
            <th>序号</th>
            <th>销售时间段(同票类不能重复)</th>
            <th>销售适用日期</th>
            <th class="col4 price_helper" title="产品每天的库存，填“-1”表示不限">日库存</th>
            <th class="col4 price_helper" title="各级分销商最低结算价,单位“元”">供货价</th>
            <th class="col5 price_helper" title="产品限制的最低零售价格,单位“元”">零售价</th>
            <th>门市价</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody id="price_body">
			
            <?
				$p_type=$ptype;
				include(TPLPATH.'product_price.html');
			?>
        </tbody>
    </table>
        <div id="toAppend" class="btnWrap mt10">
            <?=$btnWrap?>
        </div>
    </form>
</div>
<div id="alter-box" class="alter-box">
    <p id="add_result" class="alter-result"><span class="ok"></span><span id="alter-msg" class="alter-msg"></span></p>
    <?php if(!$isedit):?>
        <p class="alter-ask">您是否要添加新门票？</p>
        <p>
            <button id="to_ticket_list" back-url="<?=$gourl?>" class="ui-button ui-button-mblue" type="button">返回列表</button>
            &nbsp;&nbsp;
            <button id="add_another_ticket" class="ui-button ui-button-mblue" type="button">继续添加</button>
        </p>
    <?php else:?>
        <p>
            <button id="to_ticket_list" back-url="<?=$gourl?>" class="ui-button ui-button-mblue" type="button">返回列表</button>
            &nbsp;&nbsp;
            <button id="close_dialog" onclick="easyDialog.close();" class="ui-button ui-button-mblue" type="button">关闭</button>
        </p>
    <?php endif;?>
</div>
<script type="text/template" id="sprice">
    <tr id="sprice_{k}">
        <th>{inc}</th>
        <td>
            从<input type="text" data-t="bt" data-msg="请选择时间段" name="ticket[{k}][bt]" readonly="readonly" class="required input-text w66" id="btna" onfocus="WdatePicker({minDate:'%y-%M-{%d}'})"/>
            至<input type="text" data-t="et" data-msg="请选择时间段" name="ticket[{k}][et]" readonly="readonly" class="required input-text w66"  onFocus="WdatePicker({minDate:'#F{$dp.$D(\'btna\')}',maxDate:'2020-10-01'})"/>
        </td>
        <td>
            <a href="javascript:" class="date_chk" data-chk="1">全选</a>&nbsp;
            <a href="javascript:" class="date_chk" data-chk="2">平时</a>&nbsp;
            <a href="javascript:" class="date_chk" data-chk="3">周末</a>
            <br/>
            <label><input type="checkbox" name="ticket[{k}][normalDay][0]" checked="checked" class="pday" value="0">日</label>
            <label><input type="checkbox" name="ticket[{k}][normalDay][1]" checked="checked" class="pday" value="1">一</label>
            <label><input type="checkbox" name="ticket[{k}][normalDay][2]" checked="checked" class="pday" value="2">二</label>
            <label><input type="checkbox" name="ticket[{k}][normalDay][3]" checked="checked" class="pday" value="3">三</label>
            <label><input type="checkbox" name="ticket[{k}][normalDay][4]" checked="checked" class="pday" value="4">四</label>
            <label><input type="checkbox" name="ticket[{k}][normalDay][5]" checked="checked" class="pday" value="5">五</label>
            <label><input type="checkbox" name="ticket[{k}][normalDay][6]" checked="checked" class="pday" value="6">六</label>
        </td>
        <td>
            <input type="text" data-t="pp" title="请输入日库存量“-1”不限" value="不限" class="input-text w40 storage" name="ticket[{k}][storage]">
        </td>
        <td>
           <input type="text" data-t="pp" data-msg="请输入供货价"  class="required input-text w40" name="ticket[{k}][pg]">
        </td>
        <td>
           <input type="text" data-t="sp" data-msg="请输入零售价" class="required input-text w40" name="ticket[{k}][pl]">
        </td>
        <td>
            &nbsp;
        </td>
        <td><a href="javascript:"  data-rid="{k}" class="remvPrice">删除</a></td>
    </tr>
</script>
<script src="http://www.12301.cc/js/easydialog.min.js" type="text/javascript"></script>
<script src="http://www.12301.cc/js/ticket_edit.add.js" type="text/javascript"></script>
<script src="http://www.12301.cc/js/prod_pub.js" type="text/javascript"></script>
<script src="http://www.12301.cc/js/WdatePicker.js"></script>
<?
$src="http://www.12301.cc/js/prod_editk_v3.js?20140903";
if($_GET['sync'] && $_GET['sync']=='225800'){
    $src="http://www.12301.cc/js/prod_editk_sync.js?20140903";
}
?>
<script>
/**
 * Created with JetBrains PhpStorm.
 * User: cgp
 * Date: 13-4-10
 * Time: 下午3:22
 */
Object.countObj = function(obj) {
    var size = 0,key;
    for(key in obj) {
        if(obj.hasOwnProperty(key)) size ++;
    }
    return size;
};
var baseUrl = 'call/jh_prod_dev.php',
    pid = parseInt($("input[name='pid']").val()),
    lastid = parseInt($("input[name='lastid']").val()),
    did = parseInt($("input[name='did']").val());
var goBack = function() {
    history.go(-1);
};
var fnSaveTicket = function(){

    var res = _chkRequierd();
    if(res>0) {
        return false;
    }
    if($("textarea#ass_station").length && $.trim($("textarea#ass_station").val())=='' ){
        alert('请至少填写一个集合地点');
        return;
    }
    if(($('#radio2').attr('checked')=='checked' )&&((!$('input[name="order_end"]').val()) || (!$('input[name="order_start"]').val()))){
            alert('有效日期不能为空');
            return false;
        }
    var priceInput = $("table#ptbl").find('input:text'),
        priceText = {bt:'起始日期',et:'结束日期',pp:'供货价',sp:'零售价'},
        r2 = 0;
    $.each(priceInput,function(k,v){
         var t = $(this).attr('data-t');
        if($(this).val()=='' && t){
            r2 += 1;
            alert(priceText[t] + '不能为空');
            return false;
        }
        if(r2>0){
            r2 -= 0;
        }
    });
    if(r2>0) return false;
    var postData =  $("form#branchForm").serialize(),
        that = $(this),
        pid = parseInt($("input[name='pid']").val()),
        btnTxt = $(this).text();
    $(this).text('保存中...').attr('disabled','disabled');
    $.ajax({
        type:'POST',
        url: baseUrl,
        data: postData,
        dataType:'json',
        success: function(result){
            if(result.errcode==1000) {
                //$("input[name='lastid']").val(result.lastid);
                if(!pid) {
                    $("input[name='pid']").val(result.pid);
                }
                $("#to_ticket_list").bind('click',function(){
                    var gourl = $(this).attr('back-url')==1 ? "prodlists.html" : "ticket_list.html";
                    location.href = gourl;
                });
                if( $("#add_another_ticket").length){
                    $("#add_another_ticket").bind('click',function(){
                        location.href="prod_editk.html?sid="+landid;
                    });
                }
                $("#alter-msg").html(result.msg);
                easyDialog.open({
                    container : 'alter-box',
                    fixed : true
                });
            } else{
                alert(result.msg);
            }
        },
        timeout: 10000,
        complete:function(){
            that.text(btnTxt).removeAttr('disabled');
        },
        error : function(XMLHttpRequest, textStatus, errorThrown) {
            if(textStatus == 'timeout') {
                alert("请求已经超时,保存失败");
            } else {
                alert("其他错误,保存失败。错误信息："+errorThrown);
            }
        }
    });
};
var ue;
if($("#detailInfo").length){
    window.UEDITOR_CONFIG.initialFrameWidth = 640;
    rend_text_area = $("#detailInfo");
    ue = UE.getEditor('detailInfo');
}
jQuery(document).ready(function($){
    //产品
    if($("#area").length){
        var area,pro_id, city_id,countr_id;
        if($("input[name='area']").val()){
            area = $("input[name='area']").val().split('|'),
            por_id = area[0],city_id = area[1],country_id = area[2];
        } else {
            por_id = 12,city_id = 381,country_id = 0;
        }
        $("#area").getAreas({update:true,pro_id:por_id,
            city_id:city_id,county_id:country_id,depth:2});
    }
    $("#saler_choice").on('keyup', function(event){
        var v = $(this).val(),
            top = $(this).outerHeight(),
            width = $(this).outerWidth();
        if(v.length>=2 && pub.is_chinese(v)) {
            $("#salers_ul").empty();
            var salers_list = '';
            $.getJSON(baseUrl,{action:'FindSalers',sname:v})
                .done(function(salers){
                    for(var id in salers) {
                        salers_list += '<li data-sid="'+id+'">'+salers[id]+'</li>';
                    }
                    if(salers_list.length>0) {
                        $("#salers_ul").css({'top':top,'width':width})
                            .html(salers_list).show();
                    }
                });
        }
    });
    $("#saler_choice").on('change', function(){
        var dname = $(this).val();
        $.getJSON('call/jh_mem.php', {action:'SearchDistor',mode:1,dname:dname, dtype:2})
            .done(function(res){
                if(res.status!=='ok') {
                    $("input[name='parent_id']").val(0);
                    alert('不存在名称为“'+dname+'”的直接供应商');
                   $("#saler_choice").val('');
                }
            });
    });
    $("#salers_ul").on('click', 'li', function(){
         var sid = $(this).attr('data-sid'),
             txt = $(this).text();
        $("#saler_choice").val(txt);
       // console.log(sid + txt);
        $("input[name='parent_id']").val(sid);
//        console.log($(this).parent())
        $(this).parent().hide();
    });
    $("#salers_ul").find('li').hover(function(){
            $(this).addClass('ac_hover');
        },
        function(){
            $(this).removeClass('ac_hover');
        });
    $("select#pname").on('change',function(){
        var s = $(this).find('option:selected'),
            val = parseInt( s.val() ),
            txt = s.text();
        if(val=='other' || !val) {
            $(this).next('input').val('');
        } else {
            $(this).next('input').val(txt);
        }
    });
    var csms = $("input[name='f\[confirm_sms\]'][value='1']"),
        //mnvr = $("input[name='f\[manual_verify\]'][value='1']"),
        ats = $("#auto_c_pannel").find('select');

    $("input[name='auto_c']").bind('click',function(){
        var c = $(this).val();
        if(c==1){
            csms.attr('disabled','disabled').parent('label').addClass('disable');
            //mnvr.attr('disabled','disabled').parent('label').addClass('disable');
        } else {
            csms.removeAttr('disabled').parent('label').removeClass('disable')
            //mnvr.removeAttr('disabled').parent('label').removeClass('disable')
        }
        if(c==3){
            ats.removeAttr('disabled');
        } else {
            ats.attr('disabled','disabled');
        }
    });
    //Edit Order's notify phonenum
    var cancleEdit = function(){
        $("#edit_notify_num").text('修改').removeClass('editing');
        $("input#notify_num").attr('readonly','readonly').removeClass('notify_num_editing');
        $("#cancel_edit_num").hide();
    };
    $("#edit_notify_num").on('click',function(){
        if($(this).hasClass('editing')){
            var phonenum = $("input#notify_num").val();
            $.post(baseUrl,{'action':'EditNotifyPhonenum',phonenum:phonenum,lastid:lastid})
                .done(function(response){
                    if(response=='ok'){
                        $("#edit_res").text('保存成功').css('color','green').fadeIn('fast').fadeOut(2000);
                        cancleEdit();
                    } else {
                        alert(response);
                    }
                })
                .error(function(){
                    alert('发生错误，无法保存号码');
                });
        } else {
            $("input#notify_num").removeAttr('readonly').addClass('notify_num_editing').focus();
            $(this).text('保存').addClass('editing');
            $("#cancel_edit_num").show();
        }
    });
    $("#cancel_edit_num").on('click',cancleEdit);
    //保存门票信息
    $("button#saveTicket").bind('click',fnSaveTicket);
    $("button#saveProduct").bind('click',function(){
        var res = _chkRequierd();
        if(res>0) {
            return false;
        }
        $("input#shuchu").val($("input#shuru").val());
        var mainTitle = $("input[name='mainTitle']"),
            that = $(this),
            step = $(this).attr('data-step') || 1,
            landid = parseInt($("#mainForm").find("input[name='lastid']").val());
        if(mainTitle.val() == '' ) {
            alert('产品名称不能为空');
            mainTitle.focus();
            return;
        }
        
		// 套票跳转到指定
		uriPath = (typeof $("#package_attr").val()=='undefined') 
        ? "product_publish.html":"product_publish_tar.html";
        rend_text_area.val(ue.getContent());
        var postData = $("form#mainForm").serialize(),btnTxt = $(this).text();
		$.ajax({
		
            type:'POST',url: baseUrl,data: postData, dataType:'json',
            beforeSend:function(){
                that.text('保存中...').attr('disabled','disabled');
            },
            timeout: 10000})
            .done(function(result){
                if(result.status=='ok') {
                    if(!landid) {
                        location.href=uriPath+"?sid="+result.lastid+"&step=2";
                    } else {
                        alert(result.msg);
                    }
                } else{
                    alert(result.msg);
                }
                that.text(btnTxt).removeAttr('disabled');
            })
            .error(function(XMLHttpRequest, textStatus, errorThrown) {
                that.text(btnTxt).removeAttr('disabled');
                if(textStatus == 'timeout') {
                    alert("请求已经超时,保存失败");
                } else {
                    alert("其他错误,保存失败。");
                }
            });
    });
    // 图片上传
    $("#BtnUpload").bind('click',function(){
        if(!$("input#imgup").val().length) return;
        $("form#mainForm").submit();
        $("#waitingUpload").html('<img src="images/loading.gif" alt="图片上传中"/>图片上传中..').show();
    });
	
    // 多图片上传
    $(".BtnUpload").bind('click',function(){
        $("#mainForm").attr("action","call/uploadThumbImage_c.php");
        index = $(".BtnUpload").index($(this));
        if(!$("input.imgup").eq(index).val().length) return;
        $("#upload_mth").val(index);
        $("input.imgup").removeAttr("name").eq(index).attr("name","upfile");
        $("form#mainForm").submit();
        $(".waitingUpload").eq(index).html('<img src="images/loading.gif" alt="图片上传中"/>图片上传中..').show();
    });

    $("table#pros_tbl").on('keyup','input.chknum',function(){
        var n = $(this).val();
        if(isNaN(n)){
            $(this).val(0);
        }
    });
    $("input.input-text").live('change keyup blur',filterStr);
    //非法字符过滤EOF

    //删除门票表格BOF
    var inc = -1,key_index = $("input#key_index").length ? parseInt($("input#key_index").val()) :2;
    $(".remvPrice").live('click',function(){
        //if(index==0) return;
        var prcid = $(this).attr('data-rid');
        if($(this).attr('data-edit')==1) {
            if(!confirm('该配置已保存，您确定要删除？')) {
                return;
            }
            $.get(baseUrl,{prcid:prcid,action:'PriceRemove'},function(res){
                if(res==1000) {
                    $("tr#sprice_"+prcid).remove();
                } else {
                    alert('删除失败！');
                }
            });
        } else {
            if(inc==0){
                return;
            }
            $("#sprice_"+prcid).remove();
            key_index -= 1;
        }
    });
    $(".newprice").bind('click',function(){
        if(key_index>10) {
            alert('超出！');
            return;
        }
        var content = $("#sprice").html();
        var newcontent = content.replace(/{k}/g,inc).replace(/{inc}/g,key_index);
        $("#price_body").append(newcontent);
        inc -= 1;
        key_index += 1;
    });
    //日期快速选择BOF
    $("a.date_chk").live('click',function(){
        var t= parseInt($(this).attr('data-chk')),
            obj_list = $(this).parent().find('input.pday');
        //console.log(obj_list.length);
        switch(t){
            case 1:
                if($(this).hasClass('checked')) {
                    obj_list.removeAttr('checked');
                    $(this).removeClass('checked');
                } else {
                    obj_list.attr('checked','checked');
                    $(this).addClass('checked');
                }
                break;
            case 2:
                obj_list.removeAttr('checked');
                obj_list.each(function(){
                    if($(this).val()>0 && $(this).val()<6) {
                        $(this).attr('checked','checked');
                    }
                });
                break;
            case 3:
                obj_list.removeAttr('checked');
                obj_list.each(function(){
                    if($(this).val()==0 || $(this).val()==6) {
                        $(this).attr('checked','checked');
                    }
                });
                break;
            default :break;

        }
    });
    //日期快速选择EOF

    $("button.ext_property").on('click',function(){
        if($(this).hasClass('open')) {
            $(this).removeClass('open').text('显示');
            $("tbody#ExtendProperty").hide();
        } else {
            $(this).addClass('open').text('隐藏');
            $("tbody#ExtendProperty").show();
        }
    });

    $(".editPrice").live('click',function(){
        var prc_id = parseInt($(this).attr('data-rid')),$tr = $("tr#sprice_"+prc_id),$select = $(this).parent().siblings('td').find('select');
        if($(this).attr('editing')){
            $tr.find('input').attr('disabled','disabled').addClass('disable');
            $select.attr('disabled','disabled');
            $(this).removeAttr('editing').text('编辑');
        }
        else{
            $select.removeAttr('disabled');
            $tr.find('input').removeAttr('disabled').removeClass('disable');
            $(this).attr('editing',1).text('取消');
        }
    });
    //线路订单确认
    $("input[name='orderConfirm']").click(function(){
        if(parseInt($(this).val())==1) {
            $(this).parent('label').addClass('chkdBg');
            $("#OrderPlugWrap").show();
            $("#OrderPlugWrap").find('input:radio').removeAttr('disabled');
        } else {
            $("input[name='orderConfirm'][value='1']").parent('label').removeClass('chkdBg');
            $("#OrderPlugWrap").hide();
            $("#OrderPlugWrap").find('input:radio').attr('disabled','disabled');
        }
    });
    //线路订单取消
    $("input[name='orderCancel']").click(function(){
        if(parseInt($(this).val())==1) {
            $("input[name='canclePercent']").removeAttr('disabled');
        } else {
            $("input[name='canclePercent']").attr('disabled','disabled').val('');
        }
    });
    var chkDay = function(){
        var val = $(this).val(),cls=$(this).attr('class');
        if($(this).attr('checked')=='checked'){
            $("input."+cls+"[value='"+val+"']").removeAttr('checked');
            $(this).attr('checked','checked');
        }
    };
    //$("input.pday").live('click',chkDay)
    //平日、周末定义
    $("input.day").bind('click',chkDay);
    //层切换

    $(".tipPop").hover(function(){
        $(this).find('span.title').addClass('hover');
        var pos = $(this).position(),top=pos.top,left=pos.left;
        $(this).find(".helpTipBox").css({top:top-120,left:left+32}).show();
    },function(){
        $(this).find('span.title').removeClass('hover');
        $(this).find(".helpTipBox").hide();
    });

    $("select#uuid").change(function(){
        $("input[name='tTitle']").val($(this).find('option:selected').text());
    });

    $(".grp_num").bind('keyup change',function(){
        var n1 = $("input[name='grp_num1']").val(),
            n2 = $("select[name='grp_num2']").val(),
            n3 = '',
            d = $("input[name='ser_date']").val();
        if(n2!='') {
            n3 = '-' + n2;
        }
        $("#prev_grp_num").text(n1+d+n3);
    });


    $("a.addclom").bind('click',function(){
        setHeight($(this),'+');
    });
    $("a.cutclom").bind('click',function(){
        setHeight($(this),'-');
    });

    $("input.storage").live('focus', function(){
        if($(this).val()=='不限') {
            $(this).val('');
        }
    });
    $("input.storage").live('blur', function(){
        if($(this).val()=='') {
            $(this).val('不限');
        }
    });
    $('#confirm_wx').click(function(){
        var lid = $("input[name=lastid]").val();
        $.ajax({
            type:'POST',
            url: baseUrl,
            data: {"action": "config_confirm_wx","lastid":lid},
            dataType:'JSON',
            success: function(result){
                if(result.code==107){
                    alert(result.msg);
                    $('#confirm_wx').removeAttr('checked');
                    $('#confirm_wx0').attr('checked','checked');
                }           
            }
        })
    })
});
</script>
<?if($p_type=='C'):?>
<script src="http://www.12301.cc/js/ticket_edit_j.js" type="text/javascript"></script>
<?php else:?>
	<?if($p_type=='F'):?>
	<script src="http://www.12301.cc/js/ticket_edit_tar.js" type="text/javascript"></script>
	<?php else:?>
	<script src="http://www.12301.cc/js/ticket_edit_p.js" type="text/javascript"></script>
	<?endif;?>
<?endif;?>
<script src="http://www.12301.cc/js/Calendar.js" type="text/javascript"></script>
<?
include('common/footer.html');
?>